package groovy2

def  data_dir = "\${PG_DATA}"
data_dir = "%PG_DATA%"

def name = """source_contract
source_contract_new
source_contractCancel
source_contractProcedure
source_contractProcedureCancel
contractSign
legalentity
legalentity_bank
legalentity_customer
legalentity_ok
contract
contract_last"""

def name2 = name.split("\n")

name2.each{
println "<tablespace name=\"ts_$it\" directory=\"'$data_dir\\ts_source_$it'\"></tablespace>"
		
}

data_dir = /d:\PGDATA2/

name2.each{
	def ts = "ts_$it"
	println "CREATE TABLESPACE \"$ts\" LOCATION '$data_dir\\$ts';"
	File f = new File("$data_dir\\$ts")
	if (!f.exists()){
		f.mkdir()
	}
}

data_dir = "\${PG_DATA}"
File out = new File('createDataDir.sh')
out.withWriter { f -> 
	name2.each{
		f.println("mkdir $data_dir\\ts_source_$it") 
	}
}
